<?php
# 导入数据库接口文件
require_once 'dr-app-config.php';
require_once 'dr-app-functions.php';

# 获得用户的请求
$action = isset($_POST['action']) ? $_POST['action'] : '';
//$action = 'get_user_histories_stats';
switch ($action) {
	case 'get_all_histories_stats':
		echo dr_get_all_user_histories_stats();
		break;

	case 'get_user_histories_stats':
		echo dr_get_user_histories_stats();
		break;

	default:
		echo '';
}

function dr_get_all_user_histories_stats()
{
	global $db;

	$result = dr_db_query_sub($db, 'select * from ^record_history');

	$histories_stats = array();
	while ($row = mysql_fetch_assoc($result)) {
		$histories_stats[] = $row;
	}
	return json_encode($histories_stats);
}

function dr_get_user_histories_stats()
{
	global $db;

	$user_id = $_POST['user_id'];

	$result = dr_db_query_sub($db, 'select * from ^record_history where user_id = #', $user_id);
	if ($result && $row = mysql_fetch_assoc($result)) {
		return json_encode($row);
	} else {
		return '{"ret":0}';
	}
}